//
//  FavoriteModuleView.m
//  SecondPage
//
//  Created by xiong qi on 13-4-19.
//  Copyright (c) 2013年 winston. All rights reserved.
//

#import "FavoriteModuleView.h"
#import "../../ResourceLoader/ResourceLoader/ResourceLoader.h"
#import "../../ResourceLoader/ResourceLoader/JSONKit.h"

@implementation FavoriteModuleView
@synthesize resourcePath,templateFiles,selectIndex,parentselectIndex,selectData,categoryName,autoID;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code

    }
    return self;
}

- (NSArray *)GetTableData:(int)index
{
    return nil;
}

-(void)ReadConfig
{
    NSMutableArray * mutablearray = [NSMutableArray array];
    NSArray * array = [self GetTableData:selectIndex];
//    NSArray * array = [[ResourceLoader getInstance] getFavoriteTemplatesByPath:self.resourcePath];
    NSString * path = nil;
    NSDictionary * tabledic = nil;
    NSString * filename = nil;
    NSString * colorcode = nil;
    for (int i=0; i<[array count]; i++) {
        tabledic = [array objectAtIndex:i];
        filename = [tabledic objectForKey:CarInfo_FileName];
        colorcode = [tabledic objectForKey:CarInfo_ColorCode];
        if (colorcode == nil) {
            colorcode = @"";
        }
        
        path = [NSString stringWithFormat:@"%@/%@",self.resourcePath,filename];
        NSData * data = [NSData dataWithContentsOfFile:path];
        
        NSDictionary * dic = [data objectFromJSONData];
        if (dic) {
            NSMutableDictionary * source = [NSMutableDictionary dictionaryWithDictionary:dic];
            [source setObject:filename forKey:Favorite_FileName];
            [source setObject:self.resourcePath forKey:Favorite_Root];
            [source setObject:colorcode forKey:CarInfo_ColorCode];
            NSString * selectid = [tabledic objectForKey:[NSString stringWithFormat:@"%@ID",categoryName]];
            [source setObject:selectid==nil?@"-1":selectid forKey:Favorite_SelectID];
            [mutablearray addObject:source];
        }
        
    }
    self.templateFiles = mutablearray;
}

-(void)dealloc
{
    self.templateFiles = nil;
    self.resourcePath = nil;
    self.selectData = nil;
    self.categoryName = nil;
    self.autoID = nil;
    [super dealloc];
}

@end
